#ifndef _MOTORHEAD_H_
#define _MOTORHEAD_H_
#include "stm32f4xx_hal.h"
#include "sys.h"

#define RATE_BUF_SIZE 6

#define PID_SHOOT_MOTOR_SPEED      (10)


typedef struct{
volatile	int32_t raw_value;   		 //编码器不经处理的原始值
	int32_t last_raw_value;				 //上一次的编码器原始值
volatile	int32_t ecd_value;           //经过处理后连续的编码器值
	int32_t diff;						       //两次编码器之间的差值
	int32_t temp_count;                  //计数用
	uint8_t buf_count;					 //滤波更新buf用
	int32_t ecd_bias;					 //初始编码器值	
	int32_t ecd_raw_rate;				 //通过编码器计算得到的速度原始值
	int32_t rate_buf[RATE_BUF_SIZE];	 //buf，for filter  滤波器
	int32_t round_cnt;					 //圈数
	int32_t filter_rate;				 //速度
	int16_t Torque;                      //扭矩
volatile	float ecd_angle;			 //角度
	
}Encoder;

#define CURRENT_LIMIT(val,max)\
if(val>max)\
	val=max;\
	
extern Encoder mechanical_angle_PTZ_P;
extern Encoder mechanical_angle_PTZ_Y;
extern volatile Encoder Dial_the_motor;

extern int32_t position_hit;
extern int speed_hit;
extern int Dial_motor_speed_ref;
extern int	Dial_motor_speed_fdb;
extern u8 prepare_flag;
void GetEncoderBias_Y(volatile Encoder *v);
void GetEncoderBias_P(volatile Encoder *v);
void GetEncoderBias(volatile Encoder *v);
void EncoderProcess(volatile Encoder *v);
void EncoderProcessHIT(volatile Encoder *v);


#endif
